﻿@using NewLife.Common;
@using NewLife.Cube.Admin;
@using XCode.DataAccessLayer;
@{
    Layout = NewLife.Cube.Setting.Current.Layout;

    //ViewBag.Title = "服务器信息";
    var dbs = Model as IList<DbItem>;
}

<div class="kt-portlet">
    <div class="kt-portlet__head">
        <div class="kt-portlet__head-label">
            <h3 class="kt-portlet__head-title">
                系统数据库
            </h3>
        </div>
    </div>
    <div class="kt-portlet__body" style="overflow-x:auto;">
        <table class="table table-bordered table-hover table-striped table-condensed">
            <thead>
                <tr>
                    <th class="text-left">名称</th>
                    <th class="text-left">类型</th>
                    <th class="text-left">连接字符串</th>
                    <th class="text-right">版本</th>
                    <th class="text-left">备份</th>
                    <th class="text-left">备份并压缩</th>
                    <th class="text-center">下载表结构</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in dbs)
                {
                    var dal = DAL.Create(item.Name);
                    // 密码需要保密
                    var str = item.ConnStr;
                    if (!str.IsNullOrEmpty())
                    {
                        var ss = str.Split(";");
                        for (var i = 0; i < ss.Length; i++)
                        {
                            if (ss[i].StartsWithIgnoreCase("password=", "pass=", "pwd="))
                            {
                                ss[i] = ss[i].Substring(null, "=") + "={保密}";
                                str = ss.Join(";");
                                break;
                            }
                        }
                    }
                    var str2 = dal.Db.ConnectionString;
                    if (!str2.IsNullOrEmpty())
                    {
                        var ss = str2.Split(";");
                        for (var i = 0; i < ss.Length; i++)
                        {
                            if (ss[i].StartsWithIgnoreCase("password=", "pass=", "pwd="))
                            {
                                ss[i] = ss[i].Substring(null, "=") + "={保密}";
                                str2 = ss.Join(";");
                                break;
                            }
                        }
                    }
                    <tr>
                        <td class="text-left">@item.Name</td>
                        <td class="text-left">@item.Type</td>
                        <td class="text-left" style="max-width:600px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;" title="@str2">@str</td>
                        <td class="text-right">@item.Version</td>
                        <td class="text-left">@Html.ActionLink("备份", "Backup", new { Name = item.Name })，共 @item.Backups.ToString("n0")个</td>
                        <td class="text-left">@Html.ActionLink("备份并压缩", "BackupAndCompress", new { Name = item.Name })</td>
                        <td class="text-center">@Html.ActionLink("下载", "Download", new { Name = item.Name })</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>
